package cn.wyu.register;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.List;

@Controller
public class registerController {

    @ModelAttribute(value = "provinceList")
    public List<String> getProvinceList(){
        List<String> provinces = new ArrayList<>();
        provinces.add("广东");
        provinces.add("江苏");
        provinces.add("北京");
        provinces.add("广西");
        return  provinces;
    }

    @ModelAttribute(value = "sportInterestList")
    public List<String> getSportInterest(){
        List<String> sportInterest = new ArrayList<>();
        sportInterest.add("足球");
        sportInterest.add("篮球");
        return  sportInterest;
    }

    @RequestMapping(value = "/register.mvc",method = RequestMethod.GET)
    public String showForm(@ModelAttribute registerUser registerUser){
        return "form";
    }

    @RequestMapping(value = "/register.mvc",method = RequestMethod.POST)
    public String processForm(@ModelAttribute registerUser registerUser,Model model){
        if(!registerUser.isAgree()){
            model.addAttribute("errorMsg","请先阅读并同意该协议");
            return "form";
        }

        return "result";
    }
}
